#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "header.h"
#include "File_Operations.h"
#include "hash.h"
struct bucket *HEAD,*TEMP;
struct file_descriptor *fdesc[100];
int Used_fd;
int i=0;
int create(char *dir_name,char *f_name,char *data){	
	//struct file_descriptor *fdesc[MAN.Max_fd];
	if(ftell(vfptr)<9104) {
	printf("\n File created Successfully\n");
	strcpy(FDESC.File_name,f_name);
	strcpy(FDESC.Absolute_path,strcat(dir_name,f_name));
	hashing(FDESC.File_name); //update hash table
	/*long int a=ftell(vfptr);
	if(a==144){
	fseek(vfptr,145,SEEK_SET);// getting the cursor to the starting of the file
	printf(" cursor :%ld\n",ftell(vfptr));
	}*/
	strcpy(BLOCK.Fixed_Block_size,data);// copying the data to the char array
	printf("File Name:%s\n",FDESC.File_name);
	printf("Complete Path Of File Creation:%s\n",FDESC.Absolute_path);
        fwrite(&BLOCK,sizeof(BLOCK),1,vfptr);// for writing the data to the file from starting of the file
	printf(" cursor :%ld\n",ftell(vfptr));
	for(i=0;i<1024;i++) {
		BLOCK.Fixed_Block_size[i]=' ';
	}
	//fdesc[i]=BLOCK.Fixed_Block_size;
	//printf("data:%s\n",(*fdesc[0]));
	i++;
	MAN.Max_fd--;
	MAN.fd_in_use++;
	printf("Number of file descriptors used: %d\n",MAN.fd_in_use);
	printf("Number of filedescriptors available are: %d\n",MAN.Max_fd);

	//fseek(vfptr,0,SEEK_SET);// setting the cursor to the staring of the file
	//fread(&BLOCK,sizeof(BLOCK),1024,vfptr);// for reading the file
	//printf("Data Entered in the file is:%s\n",BLOCK.Fixed_Block_size);
	//printf("Data:",fdes[0]);
	for(i=0;i<26;i++)
		 iterate(h[i].key,h[i].b);// display of hash table
}
else{
 printf("Crossed the maximum file limit...!!! Terminating");
 exit(0);
}
return 1;
	
	
}
